package com.helasasa.maxfunds.lineofcredit.cashloan.ghana.screen.proof.subview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode
import android.util.AttributeSet
import android.view.View


class ProofGhanaFaceFrameMask(context: Context, attrs: AttributeSet? = null) :
    View(context, attrs) {

    private val lineWidth = 4F.dpToPx()

    private val circlePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = 0xFFFFFFFF.toInt()
        xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
        strokeWidth = lineWidth
        style = Paint.Style.FILL
        isAntiAlias = true
        isDither = true
        strokeCap = Paint.Cap.ROUND
        strokeJoin = Paint.Join.ROUND
    }

    private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = Color.parseColor("#5277D6")
        strokeWidth = lineWidth
        style = Paint.Style.STROKE
        strokeCap = Paint.Cap.ROUND
        strokeJoin = Paint.Join.ROUND
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        // 画圆
        val centerX = width * 1F / 2
        val centerY = height * 1F / 2
        canvas.drawCircle(centerX, centerY, centerY, circlePaint);

        // 画圆环
        val margin = 2F.dpToPx()
        canvas.drawArc(
            margin,
            margin,
            width.toFloat() - margin,
            height.toFloat() - margin,
            0F,
            360F,
            false,
            linePaint
        )
    }

    // 将 dp 转换为像素
    private fun Float.dpToPx(): Float {
        return this * context.resources.displayMetrics.density
    }
}
